<?php

declare(strict_types=1);

namespace App\CustHub\Mapper;

use App\CustHub\Model\ChPotentialUser;
use Mine\Abstracts\AbstractMapper;
use Mine\Exception\NormalStatusException;
use Mine\MineModel;

class ChPotentialUserMapper extends AbstractMapper
{
    public function assignModel()
    {
        $this->model = ChPotentialUser::class;
    }

    public function getPageList($params, bool $isScope = true, string $pageName = 'page'): array
    {
        $filter = [
            'status' => '='
        ];
        $query = $this->model::query()
            ->select(['*'])
            ->orderBy('id', 'desc');
        $query = applyFilters($query,$params, $filter);
        $paginate = $query->paginate((int)$params['pageSize'] ?? MineModel::PAGE_SIZE);;
        return $this->setPaginate($paginate);
    }

    public function delete(array $ids): bool
    {
        $delete = $this->model::query()
            ->whereIn('id', $ids)
            ->delete();
        if (!$delete) {
            throw new NormalStatusException("删除失败");
        }
        return true;
    }
}